//
//  MovieCollectionViewCell.m
//  豆瓣
//
//  Created by aaaaaa on 16/6/24.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "MovieCollectionViewCell.h"
#import "UIImageView+WebCache.h"
#import "Tools.h"
#import "MovieListModel.h"

@interface MovieCollectionViewCell ()

@property (nonatomic, retain) UIImageView *movieImageView;
@property (nonatomic, retain) UILabel *movieNameLable;

@end

@implementation MovieCollectionViewCell

- (void)dealloc
{
    [_movieImageView release];
    [_movieNameLable release];
    [_movieListModel release];
    [super dealloc];
}


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.movieImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_movieImageView];
        [_movieImageView release];
        
        self.movieNameLable = [[UILabel alloc] init];
        [self.contentView addSubview:_movieNameLable];
        [_movieNameLable release];
        
        
    }
    return self;
}


- (void)layoutSubviews{
    [super layoutSubviews];
    
   
}

- (void)setMovieListModel:(MovieListModel *)movieListModel{
    if (_movieListModel != movieListModel) {
        [_movieListModel release];
        _movieListModel = [movieListModel retain];
    }
    
    [self.movieImageView sd_setImageWithURL:[NSURL URLWithString:self.movieListModel.pic_url]];
    
    CGFloat height = [Tools getImageHeight:self.movieListModel.pic_url withWidth:self.contentView.bounds.size.width];
    self.movieImageView.frame = CGRectMake(0, (self.contentView.bounds.size.height - height) / 2, self.contentView.bounds.size.width, height);
    
    self.movieNameLable.text = self.movieListModel.movieName;
    self.movieNameLable.textAlignment = NSTextAlignmentCenter;
    self.movieNameLable.lineBreakMode =  NSLineBreakByTruncatingMiddle;
    self.movieNameLable.frame = CGRectMake(0, (self.contentView.bounds.size.height - height) / 2 + height, self.contentView.bounds.size.width, self.contentView.bounds.size.height - height);
    
}













@end
